package com.aaa.controller.api;

import com.aaa.entity.Dept;
import com.aaa.entity.OperLog;
import com.aaa.entity.User;
import com.aaa.service.DeptService;
import com.aaa.vo.DeptVo;
import com.aaa.vo.Result;
import com.aaa.vo.UserVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/system/api/dept")
public class DeptControllerApi {
    @Autowired
    private DeptService deptService;

    @GetMapping("list")
    public Result<List<Dept>> list(){
        return deptService.findAll();
    }


    //分页查询
    @PostMapping("searchDept/{currentPage}/{pageSize}")
    public Result<IPage<Dept>> searchDept(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody DeptVo deptVo){
        return deptService.findByConditions(currentPage, pageSize, deptVo);
    }

    //删除
    @DeleteMapping("delById/{id}")
    public Result delById(@PathVariable Long id){
        if (deptService.delById(id)){
            return new Result(200,"修改成功",true);
        }else {
            return  new Result(500,"修改失败",false);
        }
    }
    //添加修改
    @PostMapping("saveAndUpdate")
    public Result saveAndUpdate(Dept dept) {
        if (deptService.saveAndUpdate(dept)) {
            return new Result(200, "操作成功", true);
        } else {
            return new Result(500, "操作失败", false);
        }
    }

    //批量删除
    @PostMapping("delListById")
    public Result delListByid(@RequestBody List<Dept> deptList){
        deptList.forEach((Dept dept)->{
            deptService.removeById(dept.getDeptId());
        });
        return new Result(200,"批量删除成功",true);
    }
    }

